package com.zqh.synchronizedDemo;

import java.util.concurrent.TimeUnit;

/**
 * @author 曾庆红
 * {@code @date} 2023-10-11 20:38
 * synchronized 获得锁是可重入的 下面代码就是模拟
 */
public class T4 {
    public synchronized void m1(){
        System.out.println("m1 start");
        /*try {
            TimeUnit.SECONDS.sleep(1);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        m2();*/
        System.out.println("m1 end");
    }
    public synchronized void m2(){
        try {
            TimeUnit.SECONDS.sleep(2);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("m2");
    }

    public static void main(String[] args) {
        new TT().m1();
    }
}
class TT extends T4{
    @Override
    public synchronized void m1() {
        System.out.println("child m1 start");
        super.m1();
        System.out.println("child m1 end");
    }
}